package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;

import model.Conference;
import model.State;

/**
 * Class to create a conf litener to listen to a JComboBox of conferences.
 * @author Kevin Anderson
 * @version Autumn 2012
 */
public class ConfListener implements ActionListener {
	
	/**
	 * Field to hold the current state of the system.
	 */
	private State my_state;
	
	/**
	 * Constructor for a conference listener.
	 */
	public ConfListener() { super(); }
	
	/**
	 * Another constructor for a conf listener.
	 * @param the_state the current state of the system.
	 */
	public ConfListener(State the_state) {
		super();
		my_state = the_state;
	}
	
	/**
	 * Method to set the state.
	 * @param the_state the current state of the system.
	 */
	public void setState(final State the_state)
	{
		my_state = the_state;
	}

	/**
	 * Method to select a conference.
	 * @param arg0 the action event that triggeres the method.
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		JComboBox<Conference> cb = (JComboBox<Conference>)arg0.getSource();
        Conference conf = (Conference)cb.getSelectedItem();
        my_state.setConference(conf);
	}
}//End class confListener.